﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ExchangeCurrencyRate.Entity;
using ExchangeCurrencyRate.Providers;
using System.Configuration;

namespace ExchangeCurrencyRate.Export
{
    class Program
    {
        static void Main(string[] args)
        {
            CurrencyRateProvider provider = new CurrencyRateFileProvider();
            string currencyCodeString = ConfigurationManager.AppSettings["currencyCodes"];
            List<string> currencyCodeList = currencyCodeString.Split(',').ToList();
            for (int i = 0; i < currencyCodeList.Count; i++)
            {
                if (!provider.CheckCurrencyCode(currencyCodeList[i]))
                {
                    Console.WriteLine("Invalid currecny code: {0}", currencyCodeList[i]);
                    currencyCodeList.RemoveAt(i);
                }
            }
            ExchangeRateApiComExporter exporter = new ExchangeRateApiComExporter(currencyCodeList, provider);
            exporter.Export(DateTime.Now.Date, (curr1, curr2, rate, saveResult) =>
                {
                    Console.WriteLine("{0}|{1}|{2} - {3}", curr1, curr2, rate, saveResult ? "done" : "fail");
                });
        }
    }
}
